package com.fbs.chicken.shirodemo.user.mapper;

import com.fbs.chicken.shirodemo.user.entity.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Set;

public interface RoleMapper {
    @Delete({
        "delete from role",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @InsertProvider(type=RoleSqlProvider.class, method="insertSelective")
    int insertSelective(Role record);

    @Select({
        "select",
        "id, name, description",
        "from role",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR)
    })
    Role selectByPrimaryKey(Integer id);

    @UpdateProvider(type=RoleSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Role record);

    /**
     * 按用户id查找角色字符串集合
     * @param userId
     * @return role string set
     */
    @Select({
            "select",
            "r.name",
            "from role r",
            "inner join user_role ur",
            "on r.id = ur.role_id",
            "where ur.user_id = #{userId,jdbcType=VARCHAR}"
    })
    Set<String> findRoleStrByUserId(String userId);
}